﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/
using System;
using System.Globalization;
using System.Windows.Data;

namespace OI.Framework
{
    public class GuidToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Guid && targetType == typeof(string))
            {
                return ((Guid)value).ToString("", culture);
            }
            throw new NotImplementedException();
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string && targetType == typeof(Guid))
            {
                Guid result;
                if (Guid.TryParse((string)value, out result))
                {
                    return result;
                }
                return Guid.Empty;
            }
            throw new NotImplementedException();
        }
    }
}